/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jard.webshop.jsfbeans;

import jard.webshop.management.UserManagement;
import jard.webshop.nbp.User;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author CJP
 */
@ManagedBean(name = "usersBackingBean")
@ViewScoped
public class UsersBackingBean implements Serializable {
    
    private UserManagement um = null;
    private List<User> allUsers = new ArrayList<User>();

    /** Creates a new instance of UsersBackingBean */
    public UsersBackingBean() {
        System.out.println("Calling constructor of UsersBackingBean");
        um = UserManagement.getInstance();
        allUsers = um.getAllUsers();
    }
    
    public List<User> getAllUsers() {
        return allUsers;
    }
    
    public void invalidate(User user) {
        System.out.println("invalidate " + user);
        um.invalidateUser(user);
        
    }
    
    public void revalidate(User user) {
        System.out.println("revalidate " + user);
        um.revalidateUser(user);
        user = um.getUser(user.getEmailAddress());
    }
    
    public void clearPassword(User user) {
        System.out.println("clear password for " + user);
        um.clearPassword(user);
        user = um.getUser(user.getEmailAddress());
    }
    
    public void setEmployee(User user) {
        System.out.println("Setting to employee " + user);
        um.setEmployee(user);
        user = um.getUser(user.getEmailAddress());
    }
    
    public void setAdmin(User user) {
        System.out.println("Setting to admin " + user);
        um.setAdmin(user);
        user = um.getUser(user.getEmailAddress());
    }
    
}
